package com.ctrlspace.core.util;

public class Inet {
	public static String intToIp(int l) {
		return ((l >> 24) & 0xFF) + "." + ((l >> 16) & 0xFF) + "."
				+ ((l >> 8) & 0xFF) + "." + (l & 0xFF);
	}

	public static int ipToInt(String addr) {
		if ("0:0:0:0:0:0:0:1".equals(addr)) {
			addr = "127.0.0.1";
		}
		
		String[] addrArray = addr.split("\\.");

		int num = 0;
		for (int i = 0; i < addrArray.length; i++) {
			int power = 3 - i;

			num += ((Integer.parseInt(addrArray[i]) % 256 * Math
					.pow(256, power)));
		}

		return num;
	}
}
